package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.MyTravelTable;
import cn.wolfcode.trip.base.query.MyTravelTableQueryObject;
import cn.wolfcode.trip.base.service.IMyTravelTableService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mytraveltable")
public class MyTravelTableController {

    @Autowired
    private IMyTravelTableService myTravelTableService;

    /**
     * 根据攻略的id查询是否添加我的旅行单
     * @param strategyId
     * @return
     */
    @GetMapping
    private boolean selectTableRecord(Long strategyId,Long userId){
        boolean type = myTravelTableService.selectTableRecord(strategyId,userId);
        return type;
    }

    /**
     * 根据攻略id和用户id来保存收藏
     * @param myTravelTable
     * @return
     */
    @PostMapping
    public JSONResult saveMyTravelTableCollect (MyTravelTable myTravelTable){
        myTravelTableService.save(myTravelTable);
        return new JSONResult();
    }

    /**
     * 通过传入的用户id和游记id删除对应的收藏关系
     * @param
     * @param
     * @return
     */
    @DeleteMapping("delete")
    public JSONResult deleteMyTravelTableCollect(MyTravelTable myTravelTable){
        myTravelTableService.deleteMyTravelTable(myTravelTable);
        return new JSONResult();
    }

    /**
     * 查询当前用户所有的行程
     * @return
     */
    @GetMapping("own")
    public PageInfo selectAllTheTrip(MyTravelTableQueryObject qo){
        qo.setOrderBy("travelTime desc");
        PageInfo result = myTravelTableService.query(qo);
        return result;
    }

    /**
     * 根据用户的id,和出行状态查询所有的旅行数
     * @param qo
     * @return
     */
    @GetMapping("travelCount")
    public int selectTravelCount(MyTravelTableQueryObject qo) {
        int result = myTravelTableService.selectTravelCount(qo);
        return result;
    }

    /**
     * 根据id删除,对应的旅行单
     * @param id
     * @return
     */
    @DeleteMapping
    public JSONResult deleteMyTravel(Long id){
        myTravelTableService.deleteMyTravelTableById(id);
        return new JSONResult();
    }

    /**
     * 根据id修改用户的出行状态
     * @param id
     * @param travelStatus
     * @return
     */
    @PutMapping
    public JSONResult updateMyTravelStatus(Long id,Long travelStatus){
        myTravelTableService.updateMyTravelTableById(id,travelStatus);
        return new JSONResult();
    }
}
